/**
 * JSON.parse()原理
 * @author Thousand-paper-crane
 * @param {JSON} jsonData 
 * @returns temp
 */
function parse(javaData)
{
    let webObj={}
    javaData=javaData.replace(/{|}|"|\s/g,'')
    let javaDataArr=javaData.split(',')

    //javaDataArr.forEach(function(item){
    javaDataArr.forEach(item=>{
        let temp=item.split(':')
        let key=temp[0]
        let val=temp[1]
        webObj[key]=val
    })
    return webObj
}
// parse('{"uname:李四,"age":"18","sex":"boy"}')
let obj=parse('{"uname:李四,"age":"18","sex":"boy"}')

/**
 * JSON.stringify()原理
 * @author Thousand-paper-crane
 * @param {Object} objData 
 * @returns jsonArr
 */
function stringify(webObj)
{
    let arr = []
    for (let key in webObj)
    {
        let val=webObj[key]
        
            
            if(!['boolean','number'].includes(typeof val)){
                
                val=`"${val}"`
            }
         val=`${val}`
        arr.push(`"${key}":${val}`)
    }
    return `{${arr.join(',')}}`
}

let json=stringify({uname:'李四',age:18,sex:'boy'})
console.log(json);

